package com.study.demo;

import java.util.ArrayList;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

public class ArrayListTest {

	public static void main(String[] args){
		
		List list = new ArrayList();
		for(int i = 0; i < 1000000; i++){
			list.add(i);
		}
		
		forSort(list);
		Sort1(list);
		Sort2(list);
	}
	
	public static void forSort(List list){
		
		int len = list.size();
		int btime = (int) System.currentTimeMillis();
		for(int i = 0; i < len; i++){
			int tmp = (int) list.get(i);	
		}
		int etime = (int) System.currentTimeMillis();
		System.out.println("RandomAccess: " + (etime - btime));
	}
	
	public static void Sort1(List list){
		int btime = (int) System.currentTimeMillis();
		Iterator iterator = list.iterator();
		while(iterator.hasNext()){
			int tmp = (int) iterator.next();	
		}
		int etime = (int) System.currentTimeMillis();
		System.out.println("Iterator: " + (etime - btime));
	}
	
	public static void Sort2(List list){
		int btime = (int) System.currentTimeMillis();
		for(Object tmp1: list){
			int tmp = (int) tmp1;	
		}
		int etime = (int) System.currentTimeMillis();
		System.out.println("For2: " + (etime - btime));
	}
	
}
